<template>
	<view class="goods_list">
		<goods-list :goods="goods"></goods-list>
		<view class="isOver" v-if="flag">-----我是有底线的-----</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				pageindex:1,
				goods:[],
				flag:false
			}
		},
		components:{
			"goods-List":goodsList
		},
		onLoad() {
			this.getGoodsList()
		},
		methods: {
			//获取商品数据
			getGoodsList(callBack){
				for (var i=0;i<10;i++){
					this.goods.push({
						id: i+(this.pageindex-1)*10,
						img_url: "https://demoapi.dtcms.net/upload/202104/15/09571005-43a9-49c2-ad27-a2754363c7fb.jpg",
						sell_price:10000,
						market_price:30000,
						title:'爱代码,爱理财,爱QQ'
					});
				}
				callBack&&callBack()
			}
		},
		onReachBottom() {
			if(this.pageindex>=3){
				this.flag=true;
				return;
			}
			console.log("触底了")
			this.pageindex++;
			this.getGoodsList()
		},
		//下拉刷新事件
		onPullDownRefresh() {
			console.log("下拉刷新了")
			this.pageindex=1
			this.goods=[]
			this.flag=false
			setTimeout(()=>{
				//调用getGoodsList方法并传一个回调函数
				this.getGoodsList(()=>{
					//关闭下拉刷新
					uni.stopPullDownRefresh()
				})
			},1000)
		}
		
	}
</script>

<style>
.goods_list{
	background: #eee;
}
.isOver{
	width: 100%;
	height: 50px;
	line-height: 50px;
	text-align: center;
	font-size: 28rpx;
}
</style>
